//https://leetcode.cn/problems/longest-palindromic-substring/submissions/582439942/
class Solution {
public:
    string longestPalindrome(string s) {
        int n = s.size();
        if (n == 1)return s;
        vector<vector<bool>> dp(n, vector<bool>(n));
        int ret = 0;
        string str = "";
        for (int i = n - 1; i >= 0; --i)
        {
            for (int j = i; j < n; ++j)
            {
                if (s[i] == s[j])
                {
                    if (i == j) dp[i][j] = true;
                    else if (i + 1 == j) dp[i][j] = true;
                    else dp[i][j] = dp[i + 1][j - 1];
                }
                if (dp[i][j]) { if (ret < j - i + 1) { ret = j - i + 1; str = s.substr(i, j - i + 1); } }
            }
        }
        return str;
    }
};